﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using PowerCreator.LMS.Common.Script;

//using PowerCreator.LMS.Logic.Common;
//using PowerCreator.LMS.Model.Entity;
//using PowerCreator.LMS.Logic.PaperManager;

public partial class sysadmin_CountManager_PaperInfo : PowerCreator.LMS.Web.Base.BasePage
{
    //ManagerUserPaperHistoryInfo objUserPaperHistorylogic = new ManagerUserPaperHistoryInfo();

    protected void Page_Load(object sender, EventArgs e)
    {
        //if (!GetRole(Role.CountPaper))
        //{
        //    Script.ShowAndHistory("您没有试卷统计的权限!", -1);
        //    return;
        //}
        if (!IsPostBack)
        {

            string search = GetSearch();
            BinderPager(search);
            BinderGV(search, 1);
        }
    }
    private string GetSearch()
    {
        string search = "";
        if (!string.IsNullOrEmpty(txtPaperName.Text.Trim()))
        {
            search = string.Format(" and pf.PaperName like '%{0}%' ", txtPaperName.Text);
        }
        return search;
    }
    private void BinderPager(string search)
    {
        //AspNetPager1.RecordCount = objUserPaperHistorylogic.PaperCountListCount(search);
        //AspNetPager1.PageSize = FBasePage.PageSize();
    }
    private void BinderGV(string search, int pageIndex)
    {
        //DataTable dt = new DataTable();
        //dt = objUserPaperHistorylogic.PaperCountList(search, pageIndex, FBasePage.PageSize());
        //ViewState.Add("dt",dt);
        //dt.Columns.Add("url");
        //for (int i = 0; i < dt.Rows.Count; i++)
        //{
        //    dt.Rows[i]["url"] = "p=" + Base64.Encode(dt.Rows[i]["PaperID"].ToString()) + "&pn=" + Base64.Encode(dt.Rows[i]["PaperName"].ToString());
        //}
        //gvPaperList.DataSource = dt;
        //gvPaperList.DataBind();
    }

    protected void btnSearch_Click(object sender, EventArgs e)
    {
        string search = GetSearch();
        BinderPager(search);
        BinderGV(search, 1);
    }
    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        string search = GetSearch();
        BinderGV(search, AspNetPager1.CurrentPageIndex);
    }
    protected void gvPaperList_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        string url = string.Empty;
        if (e.CommandName == "btn_SelInfo")
        {
            url = "PaperCountUserList.aspx?"+e.CommandArgument.ToString();
            Script.RedirectURL(url);
        }
        if (e.CommandName == "btn_PassCount")
        {
            url = "FCPaper.aspx?" + e.CommandArgument.ToString();
            //rrl = "PaperPassCount.aspx?" + e.CommandArgument.ToString();
            Script.RedirectURL(url);
        }
    }
    protected void gvPaperList_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Attributes.Add("bgColor", "#F7FAFF");
            e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#FAEDB8'");
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#F7FAFF'");
        }
    }
    protected void btnExport_Click(object sender, EventArgs e)
    {
        
        DataTable dt = (DataTable)ViewState["dt"];
        ExportList(dt);
    }


    protected void btnAllPaperPass_Click(object sender, EventArgs e)
    {
        string url = "AllPaperPass.aspx";
        Script.RedirectURL(url);
    }
    private void ExportList(DataTable dt)
    {
        //ArrayList list = new ArrayList();
        //for (int i = 0; i < dt.Columns.Count; i++)
        //{
        //    if (dt.Columns[i].ColumnName == "PaperID")
        //    {
        //        dt.Columns[i].ColumnName = "试卷ID";
        //        dt.Columns[i].SetOrdinal(0);
        //    }
        //    else if (dt.Columns[i].ColumnName == "PaperName")
        //    {
        //        dt.Columns[i].ColumnName = "试卷名称";
        //        dt.Columns[i].SetOrdinal(1);
        //    }
        //    else if (dt.Columns[i].ColumnName == "sumcount")
        //    {
        //        dt.Columns[i].ColumnName = "参加人数";
        //        dt.Columns[i].SetOrdinal(2);
        //    }
        //    else
        //    {
        //        list.Add(dt.Columns[i].ColumnName);
        //    }

        //}
        //for (int i = 0; i < list.Count; i++)
        //{
        //    dt.Columns.Remove(list[i].ToString());
        //}
        //Excel objExcel = new Excel();
        //objExcel.ToExcel(dt, this.Page, "试卷统计", "试卷统计信息", "PaperInfo");
    }
    protected void btnExport_All_Click(object sender, EventArgs e)
    {
        //string search = GetSearch();
        //DataTable dt = new DataTable();
        //dt = objUserPaperHistorylogic.PaperCountList(search, 1, objUserPaperHistorylogic.PaperCountListCount(search));
        //ExportList(dt);
    }
}
